using IQIGame.Onigao.Game;
using IQIGame.Onigao.Logic;

namespace IQIGame.Onigao.GamePlay
{
    public class CFSMState_Level_Logic_Monster_Attack : CFSMState<IQIGame.Onigao.Logic.LevelEntity, CFSMLevel_Logic_MonsterData>
    {
        private float attackDelayTimer = 0;
        private LevelPlayer lockingEntityPlayer;

        public override void OnInit()
        {

        }

        public override void OnEnter(int prevStateId)
        {
            lockingEntityPlayer = data.lockingEntity.player;
            if (data.alertValue != 0)
            {
                data.alertValue = 0;
                if (data.lockingEntity != null)
                {
                    entity.ChangeAlertEnemy(data.lockingEntity, 0);
                }
            }
            data.lockingEntity = null;

            lockingEntityPlayer.region.NotifyPlayEntityAnimAction(lockingEntityPlayer, entity, LgLevelConst.AttackActionID);
        }

        public override void OnUpdate(float deltaTime)
        {
            attackDelayTimer += deltaTime;
            if (attackDelayTimer > LgLevelConst.CFSMAttackDelay)
            {
                entity.Attack(lockingEntityPlayer);
            }
        }

        public override void OnExit()
        {

        }

        public override void OnReset()
        {
            base.OnReset();
            attackDelayTimer = 0;
            lockingEntityPlayer = null;
        }
    }
}
